package com.itheima.medical.controller;
;
import com.itheima.medical.common.Algorithm;
import com.itheima.medical.common.R;
import com.itheima.medical.entity.Illinfo;
import com.itheima.medical.entity.MedicalHistory;
import com.itheima.medical.service.Medical_HistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/analyse")
public class AnalyseController {
    @Autowired
    private Medical_HistoryService medical_historyService;

    @PostMapping
    public R<String> anas(@RequestBody Illinfo illinfo){
        log.info("收到的病例信息为：{}",illinfo);

        //此处就是我们的算法，利用这个算法对我们前端收集到的数据进行加工和分析（jar包还有点问题，先写在common类里面吧）
        Algorithm algorithm = new Algorithm();
        //这里是我们算法跑出来的一个综合分数
        int Overall_scoring = algorithm.use(illinfo.getAge(),illinfo.getSex(),illinfo.getTrestbps(),illinfo.getThalach(),illinfo.getTarget());

        MedicalHistory medicalhistory= new MedicalHistory();

        //综合分数在这个区间的，代表患者罹患主动脉瓣狭窄，二尖瓣狭窄，骨性关节炎这三种疾病
        if(Overall_scoring>50&&Overall_scoring<70){
            medicalhistory.setName(illinfo.getName());
            medicalhistory.setAsa(0);
            medicalhistory.setMs(0);
            medicalhistory.setOa(0);
            medical_historyService.save(medicalhistory);
            return R.success("病例分析结束,您可能罹患主动脉瓣狭窄，二尖瓣狭窄，骨性关节炎这三种疾病");
        }
        return R.success("数据分析失败");
    }
}
